
// fontawesone
import { library } from '@fortawesome/fontawesome-svg-core'
import {fas} from '@fortawesome/free-solid-svg-icons'
import {fab} from '@fortawesome/free-brands-svg-icons'
library.add(fas,fab)
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';


//Blog 关于MTBlog封装的一些组件 导航 登录 ...
import Login from '@/components/Blog/Login/Login.vue'        //登录
import Search from '@/components/Blog/Search/Search.vue'     //搜索
import Navigation from '@/components/Blog/Navigation/Navigation.vue' //导航
import Publish from '@/components/Blog/Publish/Publish.vue'    //发布


//Tool 工具 
import Notice from '@/components/Tool/Notice/Notice.vue' //全局通知 Token失效
import Function from '@/components/Tool/Function/Function.vue' //全局的一些小功能 
import Wait from '@/components/Tool/Wait/Wait.vue' //等待
import Inform from '@/components/Tool/Inform/Inform.vue'//左侧日常通知    

//Setting 设置 
import Setting from '@/components/Setting/Setting.vue'

//Package 封装的一些简单的组件
import Background from '@/components/Package/Background/Background.vue' //背景图片
import Abnormal from '@/components/Package/Abnormal/Abnormal.vue'   //处理一些错误情况的跳转处理

//Extend 扩展
import Music from '@/components/Extend/Music/Music.vue' //音乐
import Game from '@/components/Extend/Game/Game.vue' //游戏

//时间插件
import dayjs from 'dayjs'
import relativeTime from'dayjs/plugin/relativeTime'
import updateLocale from'dayjs/plugin/updateLocale'
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
dayjs.updateLocale('en', {
	relativeTime: {
	  future: "刚刚",
	  past: "%s前",
	  s: '几秒',
	  m: "1分钟",
	  mm: "%d分钟",
	  h: "1小时",
	  hh: "%d小时",
	  d: "1天",
	  dd: "%d天",
	  M: "一个月",
	  MM: "%d个月",
	  y: "1年",
	  yy: "%d年"
	}
  })

//引入MarkDown
import VueMarkdownEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import Prism from 'prismjs';
import createHighlightLinesPlugin from '@kangc/v-md-editor/lib/plugins/highlight-lines/index';
import '@kangc/v-md-editor/lib/plugins/highlight-lines/highlight-lines.css';
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';


VueMarkdownEditor.use(createCopyCodePlugin());
VueMarkdownEditor.use(createHighlightLinesPlugin());
VueMarkdownEditor.use(vuepressTheme, {
  Prism,
  config: {
    toc: {
      includeLevel: [1, 2, 3, 4],
    },
  }
});



import store from '@/store';

export default {
    install(Vue) {
		
        Vue.component('font-awesome-icon', FontAwesomeIcon);
        Vue.component('Setting', Setting);

		Vue.component('Login', Login);
		Vue.component('Search', Search);
		Vue.component('Navigation', Navigation);
		Vue.component('Publish', Publish);

		Vue.component('Notice', Notice);
		Vue.component('Function', Function);
        Vue.component('Wait', Wait);   
		Vue.component('Inform', Inform);

		Vue.component('Background', Background);   
		Vue.component('Abnormal', Abnormal);

		Vue.component('Music', Music);
		Vue.component('Game', Game);
		
		Vue.use(VueMarkdownEditor);
        //过滤数字
        Vue.filter('count', function(value,type) {
			if(type == 'message') {
				if(value<=99) return value
				else return '99+'
			}

			//空状态
			value = parseInt(value)
			if(value==0) {
				if(type == 'information')
				return '无'
				if(type == 'hot')
				return 0
				return ''
			}

			let key = [
				{count: 100000000,name: '亿',},
				{count: 10000,name: 'W',},
				{count: 1000,name: 'K',},
			]		

			for (let i = 0; i < key.length; i += 1) {
				if (value >= key[i].count)
				return parseInt(value / key[i].count) + key[i].name + '+'
			}

			return value
		})
        //获取年龄
		Vue.filter('age', function(time) {
			if(time==null) return null
			let a = new Date(time).getTime();
			const date = new Date(a);
			const Y = date.getFullYear()
			const M = (date.getMonth() + 1)
			const D = (date.getDate())  
		
			let yy=new Date().getFullYear()
			let mm=new Date().getMonth()+1
			let dd=new Date().getDate()

			let res=yy-Y
			if(res==0)
			return '0岁'
			if(res<0)
			return null
			if(mm>M ||( mm==M && dd>=D))
			res+=1
			return res+'岁'
		})
        //过滤时间
		Vue.filter('time', function(time,type) {
			
			let a = new Date(time).getTime();
			const date = new Date(a);
			const Y = date.getFullYear() + '-';
			const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
			// const M = (date.getMonth() + 1) + '-';
			const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '  ';
			// const D = (date.getDate()) + '  '

			const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
			const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
			const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
			let yy=new Date().getFullYear()
			let mm=new Date().getMonth()+1
			let dd=new Date().getDate()
            
		
			if(type == 'simple')
			  return Y + M + D 

			if(yy==date.getFullYear() && mm==date.getMonth() + 1){

				if(dd - date.getDate() <=1 &&  type!='message')
				return dayjs(time).fromNow()
			}
			if(yy==date.getFullYear()){

				if(type == 'simple_')
			    return  M + D 

				return M+D+' '+h+m
			}
			return Y + M + D + ' ' + h+ m;
		})
		//获取歌曲进度
		Vue.filter('SongLength', function(time){
      
			let min = '',
			 sec = ''
			if (parseInt(time / 60000) < 10)
			 min = '0' + parseInt(time / 60000);
			else min = parseInt(time / 60000)
			
			let x = parseInt(time / 60000);
			if (time / 1000 - x * 60 < 10) sec = '0' + parseInt(time / 1000 - x * 60);
			else sec = parseInt(time / 1000 - x * 60);
			return min + ":" + sec
		})
		//获取文章类型
		Vue.filter('articleType', function(value,type = 'name') {
			let ArticleType = store.state.Init.ArticleTypeData
			if(! ArticleType) return '暂无类型数据,请刷新'
			let res =  ArticleType.find(item => item.id == value)
			if(res) return res[type]
			return '未找到'
		})
		//获取举报类型
		Vue.filter('reportType', function(value,type = 'name') {
				let ReportType = store.state.Init.ReportClassifyData
				if(! ReportType) return '暂无类型数据,请刷新'
				let res =  ReportType.find(item => item.id == value)
				if(res) return res[type]
				return '未找到'
			})

	    //获取举报类型
		Vue.filter('process', function(value,baseInfo) {
		    if(value == 0)
			return '正在处理中'
			if(value == 1)
			return baseInfo + '成功'
			return  baseInfo + '失败'
		})
      ////
    }
    
}
